﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml;
using System.ServiceModel.Syndication;

namespace PBDesk.Web.Main.Controllers
{
    [HandleError]
    public class FeedsController : Controller
    {
        public ActionResult Rss()
        {
            XmlTextReader xmlReader = new XmlTextReader(@"http://twitter.com/statuses/user_timeline/201858535.rss");
            SyndicationFeed myFeedInstance = SyndicationFeed.Load(xmlReader);
            return new RssActionResult() { Feed = myFeedInstance }; 
        }
    }

    public class RssActionResult : ActionResult
    {
        public SyndicationFeed Feed { get; set; } 

        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/rss+xml";
            Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(Feed);
            using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
            {
                rssFormatter.WriteTo(writer);
            } 

        }
    }
}